<?php
/**
 * ShopEx licence
 *
 * @copyright  Copyright (c) 2005-2010 ShopEx Technologies Inc. (http://www.shopex.cn)
 * @license  http://ecos.shopex.cn/ ShopEx License
 */
class ome_ctl_admin_axsupplier extends desktop_controller{
    
    var $workground = 'ome_ctl_admin_axsupplier';
    var $pagelimit = 10;
    var $axsupplier_model ;
    public function __construct($app)
    {
        parent::__construct($app);
        $this->member_model = $this->app->model('axsupplier');
        header("cache-control: no-store, no-cache, must-revalidate");
    }
   function index(){
   	
        $custom_actions[] = array('label'=>app::get('ome')->_('添加配置'),'href'=>'index.php?app=ome&ctl=admin_axsupplier&act=add_page','target'=>'dialog::{title:\''.app::get('ome')->_('添加配置').'\',width:460,height:240}');

        $actions_base['title'] = app::get('ome')->_('AX供应商配置');
        $actions_base['actions'] = $custom_actions;
        $actions_base['allow_detail_popup'] = true;
        $actions_base['use_buildin_set_tag'] = false;
        $actions_base['use_buildin_export'] = false;
        $actions_base['use_buildin_filter'] = false;

        $actions_base['use_view_tab'] = false;

        $this->finder('ome_mdl_axsupplier',$actions_base);
    }


    function add_page()
    {

        $sql = "SELECT corp_id,name from sdb_ome_dly_corp where disabled='false'";
        $dly_corp_datas = kernel::database()->select($sql);
        $this->pagedata['dly_corp'] = $dly_corp_datas;
        $this->display('admin/axsupplier/new.html');
    }

    function add(){
        $axsupplier_model = $this->app->model('axsupplier');

        $arr_order['pam_account']['logi_name'] = $_POST['pam_account']['logi_name'];
        $arr_order['pam_account']['AXsupplierCode'] = $_POST['pam_account']['AXsupplierCode'];
        $arr_order['pam_account']['AXsupplierName'] = $_POST['pam_account']['AXsupplierName'];
        $arr_order['pam_account']['effective_time'] = strtotime($_POST['pam_account']['effective_time']);
        $arr_order['pam_account']['disable_time'] = strtotime($_POST['pam_account']['disable_time']);
        
        if($_POST)
        {
            if($_POST['pam_account']['id'] != '')
            {
                // 修改
                $this->begin();

                $db = kernel::database();
                $db->beginTransaction();
                if( $axsupplier_model->update($arr_order['pam_account'], array('id' => $_POST['pam_account']['id'])) )
                {
                    $db->commit();
                }else{
                    $msg = '保存失败，请联系客服!';
                    return false;
                }
                $this->end(true, app::get('ome')->_('添加成功！'));
            } 
            else 
            {
                // 添加
                $this->begin();
                $db = kernel::database();
                $db->beginTransaction();
                if( $axsupplier_model->save($arr_order['pam_account']) )
                {
                    $db->commit();
                }else{
                    $msg = '保存失败，请联系客服!';
                    return false;
                }
                $this->end(true, app::get('ome')->_('添加成功！'));
            }
        }
    }
    function lmedit(){
        $axsupplier = '';
        if(isset($_GET['id'])){
            $id = $_GET['id'];
            $axsupplier_obj = kernel::single('ome_mdl_axsupplier');
            $axsupplier = $axsupplier_obj->getList('*', array('id'=>$id), 0, 1);

        }

        $sql = "SELECT corp_id,name from sdb_ome_dly_corp where disabled='false'";
        $dly_corp_datas = kernel::database()->select($sql);
        $this->pagedata['dly_corp'] = $dly_corp_datas;
        $this->pagedata['pam_account'] = $axsupplier[0];
        $this->page('admin/axsupplier/new.html');

    }

    //理文测试
    
}
